package com.unnamed.b.atv.sample.holder;

import com.unnamed.b.atv.model.TreeNode;
import com.unnamed.b.atv.sample.ResourceTable;
import ohos.agp.components.Component;
import ohos.agp.components.Image;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.Text;
import ohos.app.Context;

/**
 * HeaderHolder
 *
 * @author Administrator
 * @Date 2021/5/26
 */
public class HeaderHolder extends TreeNode.BaseNodeViewHolder<IconTreeItemHolder.IconTreeItem> {
    private Image arrowView;

    public HeaderHolder(Context context) {
        super(context);
    }

    @Override
    public Component createNodeView(TreeNode node, IconTreeItemHolder.IconTreeItem value) {
        Component component = LayoutScatter.getInstance(context).parse(ResourceTable.Layout_header_node, null, false);
        Text tvValue = (Text) component.findComponentById(ResourceTable.Id_node_value);
        tvValue.setText(value.getText());
        final Image iconView = (Image) component.findComponentById(ResourceTable.Id_icon);
        iconView.setPixelMap(value.getIcon());
        arrowView = (Image)  component.findComponentById(ResourceTable.Id_arrow_icon);
        if (node.isLeaf()) {
            arrowView.setVisibility(Component.INVISIBLE);
        }
        return component;
    }

    @Override
    public void toggle(boolean active) {
        arrowView.setPixelMap(active ? ResourceTable.Media_arrow_down : ResourceTable.Media_arrow_right);
    }

}
